package huaweiod.first;

import java.util.HashMap;
import java.util.Scanner;

/**
 * 华为OD机试真题 Java 实现【最多颜色的车辆】【2022.11 Q4新题】
 */
public class A_2023_08_SlidingWindowMaxColorCar {

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        String input_str = in.nextLine();
        String[] input_list = input_str.split(" ");

        int[] cars = new int [input_list.length];
        for (int i=0;i<input_list.length;i++) {
            cars[i] = Integer.parseInt(input_list[i]);
        }
        String window_size_str = in.nextLine();
        int window_size = Integer.valueOf(window_size_str);

        // 题解：滑动窗口
        int[] windows = new int[3];
        for (int i = 0; i < window_size; i++) {
            windows[cars[i]] += 1;
        }
        int res = Math.max(Math.max(windows[0],windows[1]),windows[2]);
        for (int i = window_size; i < cars.length; i++) {
            windows[cars[i]] += 1;
            windows[cars[i - window_size]] -= 1;
            res = Math.max(res,Math.max(Math.max(windows[0],windows[1]),windows[2]));
        }
        System.out.println(res);
    }
}
